<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width= , initial-scale=1.0">
    <title>Document</title>
</head>
<script src="../js/vue.js"></script>
<body>
    <h3>父访子</h3>
    <div id="app">   
       <cpn></cpn>
       <cpn ref="aaa"></cpn>
       <button @click="btnClick()">按钮</button>
    </div>
    <template id="cpn">
        <div>
          我是子组件
        </div>
      </template>
    <script>
       
        const app = new Vue({
            el: '#app',    
            data: {    
            },
            methods: {
                btnClick() {
                    // console.log(this.$children);
                    // this.$children[0].showMessage();
                
                    // $refs  => 对象类型，默认是一个空的对象
                    console.log(this.$refs.aaa.name);
                }
            },
            components: {
                cpn: {
                    template: '#cpn',
                    data () {
                        return {
                            name: '我是子组件aaa'
                        }
                    },
                    methods: {
                    showMessage() {
                        console.log('showMessage');
                    }
                   }
                }
            }


        })
        
        

    </script>

</body>
</html>